package com.douqu.game.core.config.map;

import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-09-04 19:45
 */
public class RouteConfig extends GameObject{

    public int[] cityList;

    @Override
    public boolean check()
    {
        if(cityList == null || cityList.length == 0)
        {
            LogUtils.error("Load RouteConfig check cityList is null! id:" + id);
            return false;
        }

        for(int cityId : cityList)
        {
            if(DataFactory.getInstance().getGameObject(DataFactory.CITY_KEY, cityId) == null)
            {
                LogUtils.error("Load RouteConfig check cityList is null! cityId:" + cityId + "  id:" + id);
                return false;
            }
        }
        return super.check();
    }

    @Override
    public boolean setVariable(String key, String value)
    {
        if("cityList".equals(key))
        {
            cityList = LoadUtils.loadIntArray(key, value);
            if(cityList.length == 0)
            {
                LogUtils.error("Load RouteConfig cityList is null -> value:" + value + "  id:" + id);
                return false;
            }
            return true;
        }
        else
            return super.setVariable(key, value);
    }
}
